import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

//用户中心
const Mine = ()=> import('../views/mine/Mine.vue')
const UserCenter = ()=>import ('../views/mine/children/UserCenter.vue')
const MyOrder = ()=>import ('../views/mine/children/MyOrder.vue')

//引入一级组件
import DashBoard from '../views/dashboard/DashBoard'
const Home = ()=> import('../views/home/Home.vue')
const Cart = ()=> import('../views/cart/Cart.vue')
const Category = ()=> import('../views/category/Category.vue')


//引入组件相关
const Order = () => import('../views/order/Order.vue')
const OrderDetail = () => import('../views/order/children/OrderDetails.vue')
const MyAddress = () => import('../views/order/children/MyAddress.vue')
const AddAddress = () => import('../views/order/children/children/AddAddress.vue')
const EditAddress = () => import('../views/order/children/children/EditAddress.vue')

//引入登录组件
const Login = () => import ('../views/login/Login.vue')
const SelectLogin = () => import ('../views/login/SelectLogin.vue')

const routes = [
    {
        path:'/',
        redirect:'/dashboard'
    },
    {
        path: '/dashboard',
        name: 'dashboard',
        component: DashBoard,
        children:[
            {path:'/dashboard',redirect: '/dashboard/home'},
            {path:'home',name:'home',component:Home,meta:{keepAlive:true}},
            {path:'cart',name:'cart',component:Cart},
            {path:'category',name:'category',component:Category,meta:{keepAlive:true}},
            {
                path:'mine',
                name:'mine',
                component:Mine,
                children:[
                    {path:'UserCenter', name:'UserCenter', component:UserCenter}, // 用户中心
                    {path:'MyOrder', name:'MyOrder', component:MyOrder}    //我的订单
                ]
            },
        ]
    },
    {
        path:'/confirmOrder',
        name:'order',
        component:Order,
        children: [
            {
                path:'myAddress'
                ,name:'myAddress',
                component:MyAddress,
                children:[
                    {path:'addAddress',name:'addAddress',component:AddAddress},
                    {path:'editAddress',name:'editAddress',component:EditAddress}
                ]
            },
            {
                path:'OrderDetail',
                name:'OrderDetail',
                component:OrderDetail
            }
        ]
    },
    {
        path:'/login',
        name:'login',
        component:Login
    }
]

const router = new Router({
  routes
})

export default router
